package com.py.framework.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.py.framework.common.Constants;
import com.py.framework.common.controller.SystemController;
import com.py.framework.core.common.Page;
import com.py.framework.core.helper.HttpServletHelper;
import com.py.framework.core.log.ExceptionLogger;
import com.py.framework.core.rest.support.RestServiceResult;
import com.py.framework.core.utils.DateUtils;
import com.py.framework.entity.MsgRecordEntity;
import com.py.framework.entity.SysMsgEntity;
import com.py.framework.entity.UserEntity;
import com.py.framework.service.AuthenticationService;
import com.py.framework.service.SysMsgService;
import com.py.framework.service.UserService;

/**
 * 站内消息Controller
 * @author Leegern
 * @date   2018年4月24日
 */
@RestController
@RequestMapping("/sysmsg")
public class SysMsgController extends SystemController {
	
	@Autowired
	private SysMsgService sysMsgService;
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private AuthenticationService authenticationService;
	

	/**
	 * @api {post} /sysmsg/addMsgInfo.json 添加站内消息
	 * @apiName addMsgInfo
	 * @apiVersion 0.0.1
	 * @apiGroup 站内消息管理 
	 * @apiParam {HttpServletRequest}  request 请求实例
	 * @apiParam {SysMsgEntity}  entity 消息实体
	 * @apiParam {String} msgTitle 标题
	 * @apiParam {String} msgContent 内容
	 * @apiParam {String} sendId 发件人ID
	 * @apiParam {String} linkUrl 链接地址 
	 * @apiParam {int} msgStatus 消息状态，1：未读，2：已读
	 * @apiParamExample {json} 请求参数示例
	 *  {"msgTitle":"通知","msgContent":"周五放假","sendId":10,"linkUrl":"/send/msg.do","msgStatus":1}
	 * @apiSuccess {String} code 状态码:0 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {String} data 结果集
	 * @apiSuccess {String} result
	 * @apiSuccessExample {json} 成功返回结果
	 *   {"code":0,"msg":null,"count":0,"data":null}
	 */
	@RequestMapping(value = "/addMsgInfo", method = RequestMethod.POST)
	public RestServiceResult<Object> addMsgInfo(HttpServletRequest request, @RequestBody SysMsgEntity entity) {
		RestServiceResult<Object> result = super.getSuccessRestServiceResult();
		long userId = super.pickUserId(request);
		if (userId > Constants.NUMBER_ZERO && null != entity && ! CollectionUtils.isEmpty(entity.getDetails())) {
			try {
				entity.setSendId(userId);
				sysMsgService.addMsgInfo(entity);
			} catch (Exception e) {
				result = super.getFailedRestServiceResult("添加失败！");
				ExceptionLogger.error(e);
			}
		}
		return result;
	}
	
	/**
	 * @api {post} /sysmsg/queryMsgForPage.json 分页查询站内消息列表
	 * @apiName queryMsgForPage
	 * @apiVersion 0.0.1
	 * @apiGroup 站内消息管理 
	 * @apiParam {int}  page  当前页码
	 * @apiParam {int}  limit 每页条数
	 * @apiParam {String}  msgTitle 消息标题
	 * @apiParamExample {json} 请求参数示例
	 *  {}
	 * @apiSuccess {String} code 状态码:0 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {String} data 结果集
	 * @apiSuccess {String} msgTitle 标题
	 * @apiSuccess {String} msgContent 内容
	 * @apiSuccess {String} sendName 发件人
	 * @apiSuccess {String} linkUrl 链接地址 
	 * @apiSuccess {int} msgStatus 消息状态，1：未读，2：已读
	 * @apiSuccessExample {json} 成功返回结果
	 *   {"code":0,"msg":null,"count":1,"data":[{"msgTitle":"通知","msgContent":"周五放假","sendName":"管理员","linkUrl":"/send/msg.do","msgStatus":1}]}
	 */
	@RequestMapping(value = "/queryMsgForPage", method = RequestMethod.POST)
	public RestServiceResult<List<SysMsgEntity>> queryMsgForPage(int page, int limit, String msgTitle ,@RequestParam(value="msgType",required=false,defaultValue="0")int msgType
			, HttpServletRequest request) {
		Map<String, Object> params = new HashMap<>();
		Page pager = super.getPage(page, limit);
		params.put("page", pager);
		params.put("msgTitle", msgTitle);
		params.put("msgType", msgType);
		
		String jdToken = HttpServletHelper.getUserToken(request);
		UserEntity user = null;
		 List<SysMsgEntity> datas = null;

		try {
			 user = authenticationService.getCurrentUserInfo(jdToken);
			 
			
				 params.put("userId", user.getId());
				 datas = sysMsgService.queryMsgForPage(params);
			
		} catch (Exception e) {
			ExceptionLogger.error(e);
		}
		
		
		return super.getPageSuccessRestServiceResult(pager.getTotalCount(), datas);
	}
	
	
	/**
	 * @api {post} /sysmsg/queryNoticeMsgForPage.json 分页查询消息盒子列表
	 * @apiName queryNoticeMsgForPage
	 * @apiVersion 0.0.1
	 * @apiGroup 站内消息管理 
	 * @apiParam {int}  page  当前页码
	 * @apiParam {int}  limit 每页条数
	 * @apiParam {String}  startTime 开始时间
	 * @apiParam {HttpServletRequest}  request 请求实例
	 * @apiParam {String}  endTime 截止时间
	 * @apiParam {int}  msgStatus 消息状态，1：未读，2：已读
	 * @apiParamExample {json} 请求参数示例
	 *  {}
	 * @apiSuccess {String} code 状态码:0 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {String} data 结果集
	 * @apiSuccess {String} result
	 * @apiSuccessExample {json} 成功返回结果
	 *   {"code":0,"msg":null,"count":1,"data":[{"msgTitle":"通知","msgContent":"周五放假","sendName":"管理员","linkUrl":"/send/msg.do","msgStatus":1}]}
	 */
	@RequestMapping(value = "/queryNoticeMsgForPage", method = RequestMethod.POST)
	public RestServiceResult<List<SysMsgEntity>> queryNoticeMsgForPage(int page, int limit, String startTime, @RequestParam(value="msgType",required=false,defaultValue="0")int msgType, HttpServletRequest request,
			String endTime, @RequestParam(value="msgStatus",required=false,defaultValue="0")int msgStatus) {
		RestServiceResult<List<SysMsgEntity>> result = super.getSuccessRestServiceResult();
		Map<String, Object> params = new HashMap<>();
		Page pager = super.getPage(page, limit);
		long userId = super.pickUserId(request);
		params.put("page",      pager);
		params.put("recieveId", userId);
		params.put("msgStatus", msgStatus);
		params.put("msgType", msgType);
		if (StringUtils.isNotBlank(startTime)) {
			params.put("startTime", DateUtils.convertToDateTime(startTime + " 00:00:00"));
		}
		if (StringUtils.isNotBlank(endTime)) {
			params.put("endTime", DateUtils.convertToDateTime(endTime + " 23:59:59"));
		}
		List<SysMsgEntity> datas = sysMsgService.queryNoticeMsgForPage(params);
		result.setCount(pager.getTotalCount());
		result.setData(datas);
		return result;
	}
	
	/**
	 * @api {post} /sysmsg/getAreasByPid.json 获取区域数据
	 * @apiName getAreasByPid
	 * @apiVersion 0.0.1
	 * @apiGroup 站内消息管理 
	 * @apiParam {long}  parentId 父区域ID
	 * @apiParamExample {json} 请求参数示例
	 *  {}
	 * @apiSuccess {String} code 状态码:0 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {String} data 结果集
	 * @apiSuccess {long} areaId 区域Id
	 * @apiSuccess {String} areaName 区域名称
	 * @apiSuccess {String} parentAreaId 父区域Id
	 * @apiSuccess {int} count 总数
	 * @apiSuccessExample {json} 成功返回结果
	 *   {"code":0,"msg":null,"count":1,"data":[{"areaId":10,"areaName":"南京市","parentAreaId":1,"count":50}]}
	 */
	@RequestMapping(value = "/getAreasByPid", method = RequestMethod.POST)
	public RestServiceResult<List<Map<String, Object>>> getAreasByPid(
			@RequestParam(value="parentId",required=false,defaultValue="0") long parentId) {
		List<Map<String, Object>> datas = sysMsgService.getAreasByPid(parentId);
		return super.getSuccessRestServiceResult(datas);
	}
	
	/**
	 * @api {post} /sysmsg/getOfficesByPid.json 获取部门数据
	 * @apiName getOfficesByPid
	 * @apiVersion 0.0.1
	 * @apiGroup 站内消息管理 
	 * @apiParam {long}  parentId 父部门ID
	 * @apiParamExample {json} 请求参数示例
	 *  {}
	 * @apiSuccess {String} code 状态码:0 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {String} data 结果集
	 * @apiSuccess {String} officeId 部门ID
	 * @apiSuccess {String} officeName 部门名称
	 * @apiSuccess {String} parentOfficeId 父部门Id
	 * @apiSuccess {int} count 总数
	 * @apiSuccessExample {json} 成功返回结果
	 *   {"code":0,"msg":null,"count":1,"data":[{"officeId":10,"officeName":"南京市","parentOfficeId":1,"count":50}]}
	 */
	@RequestMapping(value = "/getOfficesByPid", method = RequestMethod.POST)
	public RestServiceResult<List<Map<String, Object>>> getOfficesByPid(
			@RequestParam(value="parentId",required=false,defaultValue="0") long parentId) {
		List<Map<String, Object>> datas = sysMsgService.getOfficesByPid(parentId);
		return super.getSuccessRestServiceResult(datas);
	}
	
	/**
	 * @api {post} /sysmsg/getUnreadMsg.json 获取未读消息
	 * @apiName getUnreadMsg
	 * @apiVersion 0.0.1
	 * @apiGroup 站内消息管理 
	 * @apiParam {HttpServletRequest}  request 请求实例
	 * @apiParam {long}  msgId 消息Id
	 * @apiParamExample {json} 请求参数示例
	 *  {}
	 * @apiSuccess {String} code 状态码:0 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {String} data 结果集
	 * @apiSuccess {String} count 总数
	 * @apiSuccessExample {json} 成功返回结果
	 *   {"code":0,"msg":null,"count":1,"data":{"count":50}}
	 */
	@RequestMapping(value = "/getUnreadMsg", method = RequestMethod.POST)
	public RestServiceResult<Map<String, Object>> getUnreadMsg(HttpServletRequest request, 
			@RequestParam(value = "id", required = false, defaultValue = "0") long msgId) {
		Map<String, Object> result = new HashMap<>();
		List<MsgRecordEntity> datas = null;
		int count = 0;
		// long userId = super.pickUserId(request);
		datas = sysMsgService.queryMsgRecord(msgId, 0, Constants.MSG_UNREAD);
		if (! CollectionUtils.isEmpty(datas)) {
			count = datas.size();
			UserEntity user = null;
			for (MsgRecordEntity entity : datas) {
				user = userService.findOneUser(entity.getRecieveId());
				if (null != user) {
					entity.setRecieveName(user.getUsername());
				}
			}
		}
		result.put("datas", datas);
		result.put("count", count);
		return super.getSuccessRestServiceResult(result);
	}
	
	/**
	 * @api {post} /sysmsg/getReadMsg.json 获取已读消息
	 * @apiName getReadMsg
	 * @apiVersion 0.0.1
	 * @apiGroup 站内消息管理 
	 * @apiParam {HttpServletRequest}  request 请求实例
	 * @apiParam {long}  msgId 消息Id
	 * @apiParamExample {json} 请求参数示例
	 *  {}
	 * @apiSuccess {String} code 状态码:0 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {String} data 结果集
	 * @apiSuccess {String} count 总数
	 * @apiSuccessExample {json} 成功返回结果
	 *   {"code":0,"msg":null,"count":1,"data":{"count":50}}
	 */
	@RequestMapping(value = "/getReadMsg", method = RequestMethod.POST)
	public RestServiceResult<Map<String, Object>> getReadMsg(HttpServletRequest request,
			@RequestParam(value = "id", required = false, defaultValue = "0") long msgId) {
		Map<String, Object> result = new HashMap<>();
		List<MsgRecordEntity> datas = null;
		int count = 0;
		// long userId = super.pickUserId(request);
		datas = sysMsgService.queryMsgRecord(msgId, 0, Constants.MSG_READ);
		if (!CollectionUtils.isEmpty(datas)) {
			count = datas.size();
			UserEntity user = null;
			for (MsgRecordEntity entity : datas) {
				user = userService.findOneUser(entity.getRecieveId());
				if (null != user) {
					entity.setRecieveName(user.getUsername());
				}
			}
		}
		result.put("datas", datas);
		result.put("count", count);
		return super.getSuccessRestServiceResult(result);
	}

	/**
	 * 
	 * @api {get} /sysmsg/getMsgs.json 获取已读未读消息
	 * @apiName getMsgs
	 * @apiVersion 0.0.1
	 * @apiGroup 站内消息管理
	 * @apiParam {long} msgId 消息Id
	 * @apiParamExample {json} 请求参数示例
	 *                  {"msgId":1}
	 * @apiSuccess {String} code 状态码:1 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {String} data 结果集
	 * @apiSuccess {String} result
	 * @apiSuccessExample {json} 成功返回结果
	 *                    {}
	 */
	@RequestMapping(value = "/getMsgs", method = RequestMethod.POST)
	public RestServiceResult<Map<String, Object>> getMsgs(HttpServletRequest request,
			@RequestParam(value = "id", required = false, defaultValue = "0") long msgId) {
		Map<String, Object> result = new HashMap<>();
		List<MsgRecordEntity> unreadMsg = null;
		List<MsgRecordEntity> readMsg = null;
		long userId = super.pickUserId(request);
		unreadMsg = sysMsgService.queryReadOrNot(msgId, userId, Constants.MSG_UNREAD);
		readMsg = sysMsgService.queryReadOrNot(msgId, userId, Constants.MSG_READ);
		result.put("unreadMsgCount", CollectionUtils.isEmpty(unreadMsg) ? 0 : unreadMsg.size());
		result.put("readMsgCount", CollectionUtils.isEmpty(readMsg) ? 0 : readMsg.size());
		result.put("unreadMsg", unreadMsg);
		result.put("readMsg", readMsg);
		return super.getSuccessRestServiceResult(result);
	}

	/**
	 * @api {post} /sysmsg/findOneMsg.json 根据消息Id获取消息
	 * @apiName findOneMsg
	 * @apiVersion 0.0.1
	 * @apiGroup 站内消息管理 
	 * @apiParam {long}  id 消息Id
	 * @apiParamExample {json} 请求参数示例
	 *  {}
	 * @apiSuccess {String} code 状态码:0 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {String} data 结果集
	 * @apiSuccess {String} msgTitle 标题
	 * @apiSuccess {String} msgContent 内容
	 * @apiSuccess {String} sendName 发件人
	 * @apiSuccess {String} linkUrl 链接地址 
	 * @apiSuccess {int} msgStatus 消息状态，1：未读，2：已读
	 * @apiSuccessExample {json} 成功返回结果
	 *   {"code":0,"msg":null,"count":1,"data":{"msgTitle":"通知","msgContent":"周五放假","sendName":"管理员","linkUrl":"/send/msg.do","msgStatus":1}}
	 */
	@RequestMapping(value = "/findOneMsg", method = RequestMethod.POST)
	public RestServiceResult<SysMsgEntity> findOneMsg(long id) {
		SysMsgEntity data = null;
		if (id > Constants.NUMBER_ZERO) {
			data = sysMsgService.findOneMsg(id);
		}
		return super.getSuccessRestServiceResult(data);
	}
	
	/**
	 * @api {post} /sysmsg/findOneNoticeMsg.json 根据消息Id获取消息通知
	 * @apiName findOneNoticeMsg
	 * @apiVersion 0.0.1
	 * @apiGroup 站内消息管理 
	 * @apiParam {long}  id 消息Id
	 * @apiParamExample {json} 请求参数示例
	 *  {}
	 * @apiSuccess {String} code 状态码:0 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {String} data 结果集
	 * @apiSuccess {String} msgTitle 标题
	 * @apiSuccess {String} msgContent 内容
	 * @apiSuccess {String} sendName 发件人
	 * @apiSuccess {String} linkUrl 链接地址 
	 * @apiSuccess {int} msgStatus 消息状态，1：未读，2：已读
	 * @apiSuccessExample {json} 成功返回结果
	 *   {"code":0,"msg":null,"count":1,"data":{"msgTitle":"通知","msgContent":"周五放假","sendName":"管理员","linkUrl":"/send/msg.do","msgStatus":1}}
	 */
	@RequestMapping(value = "/findOneNoticeMsg", method = RequestMethod.POST)
	public RestServiceResult<SysMsgEntity> findOneNoticeMsg(long id) {
		SysMsgEntity data = null;
		if (id > Constants.NUMBER_ZERO) {
			data = sysMsgService.findOneNoticeMsg(id);
		}
		return super.getSuccessRestServiceResult(data);
	}
	
	/**
	 * @api {post} /sysmsg/updateMsgInfo.json 更新站内消息
	 * @apiName updateMsgInfo
	 * @apiVersion 0.0.1
	 * @apiGroup 站内消息管理 
	 * @apiParam {SysMsgEntity}  entity 消息实体
	 * @apiParam {long} id 消息Id
	 * @apiParam {String} msgTitle 标题
	 * @apiParam {String} msgContent 内容
	 * @apiParam {String} sendId 发件人ID
	 * @apiParam {String} linkUrl 链接地址 
	 * @apiParam {int} msgStatus 消息状态，1：未读，2：已读
	 * @apiParamExample {json} 请求参数示例
	 *  {}
	 * @apiSuccess {String} code 状态码:0 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {String} data 结果集
	 * @apiSuccess {String} result
	 * @apiSuccessExample {json} 成功返回结果
	 *    {"code":0,"msg":null,"count":0,"data":null}
	 */
	@RequestMapping(value = "/updateMsgInfo", method = RequestMethod.POST)
	public RestServiceResult<Object> updateMsgInfo(@RequestBody SysMsgEntity entity) {
		RestServiceResult<Object> result = super.getSuccessRestServiceResult();
		if (null != entity && ! CollectionUtils.isEmpty(entity.getDetails())) {
			try {
				sysMsgService.updateMsgInfo(entity);
			} catch (Exception e) {
				result = super.getFailedRestServiceResult("更新失败！");
				ExceptionLogger.error(e);
			}
		}
		return result;
	}
	
	/**
	 * @api {post} /sysmsg/updateMsgRecordStatus.json 更新消息记录状态
	 * @apiName updateMsgRecordStatus
	 * @apiVersion 0.0.1
	 * @apiGroup 站内消息管理 
	 * @apiParam {long}  recordId 消息记录Id
	 * @apiParam {int}  msgStatus 消息状态, 1：未读，2：已读
	 * @apiParamExample {json} 请求参数示例
	 *  {}
	 * @apiSuccess {String} code 状态码:0 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {String} data 结果集
	 * @apiSuccess {String} result
	 * @apiSuccessExample {json} 成功返回结果
	 *    {"code":0,"msg":null,"count":0,"data":null}
	 */
	@RequestMapping(value = "/updateMsgRecordStatus", method = RequestMethod.POST)
	public RestServiceResult<Object> updateMsgRecordStatus(long recordId, int msgStatus) {
		RestServiceResult<Object> result = super.getSuccessRestServiceResult();
		if (recordId > Constants.NUMBER_ZERO && msgStatus > Constants.NUMBER_ZERO) {
			try {
				sysMsgService.updateMsgRecordStatus(recordId, msgStatus);
			} catch (Exception e) {
				result = super.getFailedRestServiceResult("更新失败！");
				ExceptionLogger.error(e);
			}
		}
		return result;
	}
	
	/**
	 * @api {post} /sysmsg/batchDelMsg.json 批量删除消息
	 * @apiName batchDelMsg
	 * @apiVersion 0.0.1
	 * @apiGroup 站内消息管理 
	 * @apiParam {String}  ids 消息Id集合
	 * @apiParamExample {json} 请求参数示例
	 *  {}
	 * @apiSuccess {String} code 状态码:0 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {String} data 结果集
	 * @apiSuccessExample {json} 成功返回结果
	 *   {"code":0,"msg":null,"count":0,"data":null}
	 */
	@RequestMapping(value = "/batchDelMsg", method = RequestMethod.POST)
	public RestServiceResult<Object> batchDelMsg(String ids) {
		RestServiceResult<Object> result = super.getSuccessRestServiceResult();
		if (StringUtils.isNotBlank(ids)) {
			try {
				sysMsgService.batchDelMsg(super.convert2Long(ids));
			} catch (Exception e) {
				result = super.getFailedRestServiceResult("删除失败！");
				ExceptionLogger.error(e);
			}
		}
		return result;
	}
	
	/**
	 * @api {post} /sysmsg/batchDelMsgRecord.json 批量删除消息记录
	 * @apiName batchDelMsgRecord
	 * @apiVersion 0.0.1
	 * @apiGroup 站内消息管理 
	 * @apiParam {String}  ids 消息Id集合
	 * @apiParamExample {json} 请求参数示例
	 *  {}
	 * @apiSuccess {String} code 状态码:0 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {String} data 结果集
	 * @apiSuccess {String} result
	 * @apiSuccessExample {json} 成功返回结果
	 *   {"code":0,"msg":null,"count":0,"data":null}
	 */
	@RequestMapping(value = "/batchDelMsgRecord", method = RequestMethod.POST)
	public RestServiceResult<Object> batchDelMsgRecord(String ids) {
		RestServiceResult<Object> result = super.getSuccessRestServiceResult();
		if (StringUtils.isNotBlank(ids)) {
			try {
				sysMsgService.batchDelMsgRecord(super.convert2Long(ids));
			} catch (Exception e) {
				result = super.getFailedRestServiceResult("删除失败！");
				ExceptionLogger.error(e);
			}
		}
		return result;
	}
	
	/**
	 * 
	 * @api {get} /sysmsg/getUnreadNum.json 获取未读消息数量
	 * @apiName getUnreadNum
	 * @apiVersion 0.0.1
	 * @apiGroup 站内消息管理
	 * @apiSuccess {String} code 状态码:1 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {Integer} data 未读消息数量
	 * @apiSuccessExample {json} 成功返回结果
	 *                    {}
	 */
	@RequestMapping(value = "/getUnreadNum", method = RequestMethod.POST)
	public RestServiceResult<Integer> getUnreadNum(HttpServletRequest request) {
		RestServiceResult<Integer> result = super.getSuccessRestServiceResult();
		try {
			long userId = super.pickUserId(request);
			int num = sysMsgService.getUnreadNum(userId);
			result.setData(num);
		} catch (Exception e) {
			result = super.getFailedRestServiceResult("获取未读消息数量失败！");
			ExceptionLogger.error(e);
		}
		return result;
	}

	/**
	 * 初始化日期绑定格式
	 * @param binder
	 */
//	@InitBinder  
//	public void initBinder(WebDataBinder binder) {
//		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
//		dateFormat.setLenient(false);
//		binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));  // true:允许输入空值，false:不能为空值
//	}
}